import localForage from 'localforage'
//离线缓存
export function setLocalForage(key, data){
    return localForage.setItem(key, data)
}

export function getLocalForage(key){
    return localForage.getItem(key)
}

export function removeLocalForage(key){
    return localForage.removeItem(key)
}

export function clearLocalForage(){
    return localForage.clear()
}

export function lengthLocalForage(cb){
    localForage.length().then(
        numberOfKeys => {
            if(cb) cb(numberOfKeys)
        }
    ).catch(err=>{
        console.log(err)
    })
}

export function iteratorLocalForage(){
    localForage.iterate((value,key,iterationNumber)=>{
        console.log([key,value])
        console.log(iterationNumber)
    }).then(()=>{
        console.log('iteration has completed')
    }).catch(err=>{
        console.log(err)
    })
}

export function support(){
    const indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || null
    if(indexedDB){
        return true
    }else{
        return false
    }
}